<?php
/**
 * Created by PhpStorm.
 * User: gaochaolyf
 * Date: 16/5/17
 * Time: 下午2:40
 */

namespace api\Model;

use Think\Model;

class IntegerEntityModel extends Model
{
    function __construct() {
        $this->model = M('IntegerEntity');
        $this->model1 = M('ConfigSet');
    }

    public function getIntegerList($condition = array(),$field = array('*'), $page = 1, $pergage = 10, $order = 'integer_id ASC') {
        $data = $this->model->where($condition)->field($field)->page($page, $pergage)->order($order)->select();
        foreach ($data as $key=>$val){
            $data[$key]['allnum'] = $this->model->where($condition)->field($field)->count();
        }
        $data = $data ? $data : array();
        return $data;
    }

    public function getOneInteger($field = array('*'), $condition = array()) {
        $data = $this->model->where($condition)->field($field)->find();
        $data = $data ? $data : array();
        return $data;
    }

    public function getIntegerById($integer_id = 0, $field = array('*')) {
        $data = $this->model->where(array('integer_id' => $integer_id))->field($field)->find();
        $data = $data ? $data : array();
        return $data;
    }

    public function getCountByRoleId($role_id = 0) {
        $count = $this->model->where(array('integer_role_id' => $role_id, 'delete_at' => 0))->count();
        return $count;
    }

    public function getIntegerIdByRoleId($role_id = 0, $field = array('integer_id')) {
        $data = $this->model->where(array('integer_role_id' => $role_id, 'delete_at' => 0))->order('integer_id ASC')->field($field)->select();
        $data = $data ? $data : array();
        return $data;
    }

  //美容须知
    public function BeautyTips() {
        $data = $this->model1->where(array('id' => 17))->field('config_val')->find();
        return $data;
    }


}